# backend/routers/admin_router.py
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session

from backend.crud import user_crud, library_crud
from backend.database import get_db
from backend.dependencies import get_current_active_user
from backend.schemas import User

router = APIRouter()


@router.get("/users", response_model=list[User])
def get_all_users(
        db: Session = Depends(get_db),
        current_user: User = Depends(get_current_active_user)
):
    if not current_user.is_admin:
        raise HTTPException(status_code=403, detail="无权访问")
    return user_crud.get_all_users(db)


@router.delete("/libraries/{library_id}")
def deactivate_library(
        library_id: int,
        db: Session = Depends(get_db),
        current_user: User = Depends(get_current_active_user)
):
    if not current_user.is_admin:
        raise HTTPException(status_code=403, detail="无权访问")
    return library_crud.deactivate_library(db, library_id)
